package com.edoomath.api.dao;

import java.util.List;

import com.demo2do.core.persistence.annotation.Dao;
import com.demo2do.core.persistence.annotation.Query;
import com.demo2do.core.persistence.annotation.Variable;
import com.edoomath.entity.course.CourseItem;
import com.edoomath.entity.course.CourseMaterail;
import com.edoomath.entity.course.CourseMaterialCategory;

/**
 * 
 * @author mohanlan
 *
 */
@Dao(value = "hibernate")
public interface CourseMaterialDao {
	
	/**
     * 
     * @param id
     * @return
     */
    @Query("FROM CourseMaterail WHERE id = :id AND disabled = false")
    public CourseMaterail loadCourseMaterail(@Variable("id") Long id);
    
    /**
     * 
     * @param courseItemId
     * @return
     */
    @Query("FROM CourseMaterail WHERE disabled = false AND courseItem.id = :courseItemId ORDER BY type ASC, sorting ASC")
    public List<CourseMaterail> listMaterials(@Variable("courseItemId") Long courseItemId);
    
    /**
     * 
     * @param courseItem
     * @param types
     * @return
     */
    @Query("FROM CourseMaterail WHERE courseItem = :courseItem AND type in (:types) AND disabled = false ORDER BY type ASC, sorting ASC")
    public List<CourseMaterail> listMaterials(@Variable("courseItem") CourseItem courseItem, @Variable("types") List<String> types);
    
    /**
     * 
     * @param category
     * @return
     */
    @Query("FROM CourseMaterail WHERE category = :category AND disabled = false ORDER BY type ASC, sorting ASC")
    public List<CourseMaterail> listMaterials(@Variable("category") CourseMaterialCategory category);
    
    /**
     * 
     * @param category
     * @return
     */
    @Query("FROM CourseMaterail WHERE category = :category AND disabled = false ORDER BY type ASC, sorting ASC")
    public CourseMaterail loadMaterial(@Variable("category") CourseMaterialCategory category);
    
    /**
     * 
     * @param courseItem
     * @param type
     * @return
     */
    @Query("FROM CourseMaterail WHERE courseItem = :courseItem AND type = :type AND disabled = false ORDER BY type ASC, sorting ASC")
    public CourseMaterail loadMaterialsZip(@Variable("courseItem") CourseItem courseItem, @Variable("type") String type);
    

}
